#include "PointManager.h"

#include <QUuid>
#include <QSharedPointer>

PointManager::PointManager(QObject *parent) : QObject(parent)
{
}

QSharedPointer<Point> PointManager::AddPoint(const QString &name)
{
    QSharedPointer<Point> point(new Point());
    point->SetId(QUuid::createUuid().toString());
    point->SetName(name);
    points.push_back(point);
    showPoints.push_back(point);
    return point;
}

QSharedPointer<Point> PointManager::GetPoint(const QString &id) const
{
    for (auto point : points)
    {
        if (point->GetId() == id)
        {
            return point;
        }
    }
    return nullptr;
}

QList<QSharedPointer<Point>> PointManager::GetPoints() const
{
    return points;
}

QList<QSharedPointer<Point>> PointManager::GetPoints(const QStringList &ids) const
{
    QList<QSharedPointer<Point>> pointList;
    for (auto id : ids)
    {
        pointList.push_back(GetPoint(id));
    }
    return pointList;
}

void PointManager::SetShowPoints(const QStringList &ids)
{
    this->showPoints = GetPoints(ids);
}

void PointManager::SetShowPoints(const QList<QSharedPointer<Point>> &showPoints)
{
    this->showPoints = showPoints;
}

QList<QSharedPointer<Point>> PointManager::GetShowPoints() const
{
    return showPoints;
}

void PointManager::ClearPoints()
{
    points.clear();
    showPoints.clear();
}

void PointManager::SetTimes(const QStringList &times)
{
    this->times = times;
}

QStringList PointManager::GetTimes() const
{
    return times;
}
